$(function() {
	
	juicer.set({
	    'tag::operationOpen': '-~',
	    'tag::operationClose': '+',
	    'tag::interpolateOpen': '#-',
	    'tag::interpolateClose': '+',
	    'tag::noneencodeOpen': '##-',
	    'tag::noneencodeClose': '+',
	    'tag::commentOpen': '-*',
	    'tag::commentClose': '+'
	});
	
	
	var ctx = $("input[type='hidden']").val();
	
	localStorage.setItem('ctx', ctx);
	
	
	//判断是否是超级管理员
	$.ajax({
		type: 'POST',
		url: ctx+'/sys/v1/isAdmin',
		dataType: 'json',
		success: function(data) {
			if(data == true) {
				localStorage.setItem('isAdmin','true');
			}
			else {
				localStorage.setItem('isAdmin','false');
			}
		}
	});
	
	
	
	
	
	$.ajax({
		type: 'POST',
		url: ctx+'/resource/list',
		dataType: 'json',
		success: function(data) {
			console.log(data);
			
			/*var loginname = localStorage.getItem('loginname');
			console.log(loginname);
			$(".loginname").html(loginname);*/
			
			var tpl = document.getElementById("indexLeftMenuTpl").innerHTML;
			var html = juicer(tpl, data);
			$(".sidebar-collapse").html(html);
			
			
			//左侧菜单收缩
			$('#side-menu').metisMenu();
			
			//通过遍历给菜单项加上data-index属性
			$(".J_menuItem").each(function (index) {
			    if (!$(this).attr('data-index')) {
			        $(this).attr('data-index', index);
			    }
			});
			
			$('.J_menuItem').on('click', menuItem);
			
			$('.J_menuTabs').on('click', '.J_menuTab i', closeTab);
			
			$('.J_tabCloseOther').on('click', closeOtherTabs);
			
			$('.J_tabShowActive').on('click', showActiveTab);
			
			$('.J_menuTabs').on('click', '.J_menuTab', activeTab);

			$('.J_menuTabs').on('dblclick', '.J_menuTab', refreshTab);

			// 左移按扭
			$('.J_tabLeft').on('click', scrollTabLeft);

			// 右移按扭
			$('.J_tabRight').on('click', scrollTabRight);
			
			// 关闭全部
			$('.J_tabCloseAll').on('click', function () {
			    $('.page-tabs-content').children("[data-id]").not(":first").each(function () {
			        $('.J_iframe[data-id="' + $(this).data('id') + '"]').remove();
			        $(this).remove();
			    });
			    $('.page-tabs-content').children("[data-id]:first").each(function () {
			        $('.J_iframe[data-id="' + $(this).data('id') + '"]').show();
			        $(this).addClass("active");
			    });
			    $('.page-tabs-content').css("margin-left", "0");
			});
			
			
		}
	});
	
	//退出
	$(".loginout").on('click', function() {
		/*$.ajax({
			type: 'POST',
			url: ctx+'/sys/v1/logout',
			dataType: 'json',
			success: function(data) {
				console.log(data);
			}
		});*/
		window.location.href= ctx+'/sys/v1/logout';
	});
	
});
